package com.study.studyroom.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.study.studyroom.constant.ApiConstant;
import com.study.studyroom.entity.bo.OptionBo;
import com.study.studyroom.entity.bo.RequestResult;
import com.study.studyroom.entity.bo.RoomTypeBo;
import com.study.studyroom.entity.enums.UnitTypeEnum;
import com.study.studyroom.entity.vo.Condition;
import com.study.studyroom.entity.vo.room.RoomTypeVo;
import com.study.studyroom.service.RoomTypeService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping(ApiConstant.API_V1+"roomType")
public class RoomTypeController {

    private final RoomTypeService roomTypeService;

    @ApiOperation("分页获取自习室类型")
    @PostMapping("/getRoomType")
    public RequestResult<IPage<RoomTypeBo>> getRoomType(@RequestBody Condition<RoomTypeVo> condition){
        return RequestResult.success(roomTypeService.getRoomType(condition));
    }

    @ApiOperation("获取所有自习室类型")
    @GetMapping("/getAllRoomType")
    public RequestResult<List<RoomTypeBo>> getAllRoomType(){
        return RequestResult.success(roomTypeService.getAllRoomType());
    }

    @ApiOperation("新增自习室类型")
    @PostMapping("/addRoomType")
    public RequestResult<Integer> addRoomType(@RequestBody RoomTypeVo roomTypeVo){
        return RequestResult.success(roomTypeService.addRoomType(roomTypeVo));
    }
    //修改
    @ApiOperation("更新自习室类型")
    @PutMapping("/updateRoomType")
    public RequestResult<RoomTypeBo> updateRoomType(@RequestBody RoomTypeVo roomTypeVo){
        return RequestResult.success(roomTypeService.updateRoomType(roomTypeVo));
    }
    //停用
    @ApiOperation("起停用自习室类型")
    @GetMapping("/updateRoomTypeStatus")
    public RequestResult<RoomTypeBo> updateRoomTypeStatus(Integer id){
        return RequestResult.success(roomTypeService.updateRoomTypeStatus(id));
    }
    //删除
    @ApiOperation("删除自习室类型")
    @GetMapping ("/deleteRoomType")
    public RequestResult<Integer> deleteRoomType(Integer id){
        return RequestResult.success(roomTypeService.deleteRoomType(id));
    }
    @ApiOperation("获取所有单位时间类型")
    @GetMapping ("/getAllUnitType")
    public RequestResult<List<OptionBo>> getAllUnitType(){
        List<OptionBo> result =new ArrayList<>();
        for (UnitTypeEnum value : UnitTypeEnum.values()) {
            result.add(new OptionBo(value.getCode(),value.getDesc()));
        }
        return RequestResult.success(result);
    }
}
